<template>
  <el-dialog title="添加经济" :visible="showDialog" @close="closeFn">
    <el-form ref="form" :model="formData" label-width="120px" :rules="rules">
      <el-form-item label="名称:" prop="name">
        <el-input v-model="formData.name" placeholder="请输入名称" />
      </el-form-item>
      <el-form-item label="邮箱:" prop="email">
        <el-input v-model="formData.email" placeholder="请输入邮箱" />
      </el-form-item>
      <el-form-item label="电话:" prop="phone">
        <el-input v-model="formData.phone" placeholder="请输入电话" />
      </el-form-item>
      <el-form-item label="地址:" prop="address">
        <el-input v-model="formData.address" placeholder="请输入地址" />
      </el-form-item>
      <el-form-item label="描述:" prop="desc">
        <el-input v-model="formData.desc" placeholder="请添加描述" />
      </el-form-item>
      <el-form-item label="封面" prop="image">
        <el-input v-model="formData.image" placeholder="请添加封面" />
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-row type="flex" justify="center">
        <el-button type="primary" @click="submit">添加</el-button>
        <el-button @click="closeFn">取消</el-button>

      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { addagents, updataagents } from '@/api/agents'
export default {
  inject: ['reload'],

  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formData: {
        name: '',
        email: '',
        phone: '',
        address: '',
        desc: '',
        image: ''
      },
      rules: {
        name: [
          { required: true, message: '名称不能为空', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '邮箱不能为空', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '联系方式不能为空', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '地址不能为空', trigger: 'blur' }
        ],
        desc: [
          { required: true, message: '描述不能为空', trigger: 'blur' }
        ]

      }
    }
  },

  methods: {
    // 修改
    async updatAgents(id) {
      const res = await updataagents(id)
      console.log(res)
    },
    // 新增
    async submit() {
      // 表单校验
      await this.$refs.form.validate()
      // 新增数据
      await addagents(this.formData)
      //   关闭弹窗
      this.closeFn()
    },
    // 关闭弹窗
    closeFn() {
      this.$emit('closeEvent', false)
    //   this.showDialog = false
    }
  }
}
</script>

<style>

</style>
